<!-- TODO -->
<template>
    <div>
        <el-card class="!border-none mt-4" shadow="never">
           <el-button class="mb-4" v-perms="['auth.admin/add']" type="primary" @click="handleAdd">
                新增等级
            </el-button>

            <el-table size="large" :data="pager.lists" >
				<el-table-column label="ID" prop="id">
				    <template #default="{ row }">
				        {{ row.id }}
				    </template>
				</el-table-column>
                <el-table-column label="等级名称" prop="name" min-width="120" >
                    <template #default="{ row }">
                        {{ row.name }}
                    </template>
                </el-table-column>
                <el-table-column label="等级LOGO" prop="logo" min-width="120" >
					<template #default="{ row }">
						<image-contain
							v-if="row.logo"
							:src="row.logo"
							:width="45"
							:height="45"
							:preview-src-list="[row.logo]"
							preview-teleported
							fit="contain"
						/>
					</template>
				</el-table-column>image
				<el-table-column label="直播间显示LOGO" prop="live_logo" min-width="170" >
					<template #default="{ row }">
					<image-contain
					    v-if="row.live_logo"
					    :src="row.live_logo"
					    :width="45"
					    :height="45"
					    :preview-src-list="[row.live_logo]"
					    preview-teleported
					    fit="contain"
					/>
					</template>
				</el-table-column>
                <el-table-column label="升级金额" prop="upgrade_amount" min-width="100" />
                <el-table-column label="保级金额" prop="grading_amount" min-width="100" />
				<el-table-column label="多少天更新级别" prop="days" min-width="170" />
				<el-table-column label="签到成功赠送礼品卡" prop="balance2" min-width="170" />
				<el-table-column label="签到成功赠送积分金额" prop="sign_red" min-width="180" />
				<el-table-column label="签到成功赠送优惠券" prop="coupon_id" min-width="170" />
				<el-table-column label="创建时间" prop="created_at" min-width="180" />
                <el-table-column label="操作" fixed="right" min-width="200">
                    <template #default="{ row }">
                        <el-button type="primary" @click="handleEdit(row)"> 编辑 </el-button>
                        <el-button type="primary" @click="handleDelete(row.id)">
                            封号
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>

<script lang="ts" setup>
import { usePaging } from '@/hooks/usePaging'
import { levelAllList,levelSeal} from '@/api/user'
import EditPopup from './edit.vue'
import feedback from '@/utils/feedback'
const { pager, getLists } = usePaging({
    fetchFun: levelAllList
})
getLists()
//删除
const handleDelete = async (id : any) => {
    await feedback.confirm('确定要封禁账号？')
   const ddd = await levelSeal({ level_id: id})
    getLists()
}

const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}
const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}
</script>
<style lang="scss" scope>
//TODO
.el-alert--warning.is-light {
    background-color: rgba(246, 248, 255, 1);
    color: rgba(64, 115, 250, 1);
}
</style>
